package com.bawei.base.utils

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.net.Proxy
import java.util.concurrent.TimeUnit

object RetrofitUtils {

    fun getRetrofit(): Retrofit{

        val client = OkHttpClient.Builder()
            .writeTimeout(5,TimeUnit.SECONDS)
            .readTimeout(5,TimeUnit.SECONDS)
            .connectTimeout(5,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor(TokenInterceptor())
            //封装抓包
            .proxy(Proxy.NO_PROXY)
            //考虑网络重联问题
            .addInterceptor(RetryInterceptor(20))
            .build()

        val retrofit = Retrofit.Builder()
            .client(client)
            .baseUrl(Conetant.URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()

        return retrofit

    }

}